package com.dankegongyu.screenrecord;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Build;

import androidx.localbroadcastmanager.content.LocalBroadcastManager;

/**
 * 描述：开启录屏工具类
 * 作者：ChaoZheng on 2019-12-17 03:43
 * 邮箱：chaozheng@dankegongyu.com
 */
public class DkScreenRecord {
    public static void startRecord(Context context, String recordFilePath, boolean withImg, IRecordListener stopRecordListener) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            if (null == context) {
                return;
            }
            ScreenRecordConfig.Contants.OUTPUT_FILE_DIR_DEFAULT = recordFilePath;
            ScreenRecordConfig.Contants.WIN_IMG = withImg;
            ScreenRecordConfig.stopRecordListener = stopRecordListener;
            //ScreenRecordConfig.Contants.OUTPUT_FILE_DIR_DEFAULT = Environment.getExternalStorageDirectory().getAbsolutePath();
            Intent intent = new Intent(context, PermissionActivity.class);
            if (!(context instanceof Activity)) {
                intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            }
            context.startActivity(intent);
        }
    }

    public static void startRecord(Context context, IRecordListener stopRecordListener) {
        startRecord(context, null, false, stopRecordListener);
    }

    public static void startRecordWithImg(Context context, IRecordListener stopRecordListener) {
        startRecord(context, null, true, stopRecordListener);
    }

    public static void stopRecord(Context context) {
        LocalBroadcastManager.getInstance(context).sendBroadcast(new Intent(ScreenRecordService.ACTION_STOP_RECORD));
    }
}
